% cost--weighted cdf of markups
load eq_SS
clear diff


set(0,'defaultaxesfontname','cambria math') % beautify the axes a bit
set(0,'defaultTextFontName', 'cambria math')

markup = eq_SS.pf.*exp(glob.sf(:,2));
[M,I] = sort(markup);
L = eq_SS.L(I);

y = randsample(length(L),1e6,'true',L.*eq_SS.l);
y = markup(y);
[f, xi, bw] = ksdensity(y,'Bandwidth',5*.0081);
hold on
bar(xi,f);

F = cumsum(L)/sum(L);
F = diff(F);



%plot(M(2:end),F,'LineWidth',4);
title('Markup Distribution')
set(gca,'YTickLabel',[]);



% subplot(1,3,2)
% sales = eq_SS.pf.*eq_SS.yf;
% [M,I] = sort(sales);
% L = eq_SS.L(I);
% 
% y = randsample(length(L),1e6,'true',L);
% y = sales(y);
% [f, xi] = ksdensity(y);
% 
% bar(xi,f);
% 
% 
% F = cumsum(L)/sum(L);
% F = diff(F);
% 
% %plot(M(2:end),F,'LineWidth',4);
% title('Sales')
% set(gca,'YTickLabel',[]);
% 
% subplot(1,3,3)
% emp = eq_SS.l;
% [M,I] = sort(emp);
% L = eq_SS.L(I);
% 
% F = cumsum(L)/sum(L);
% F = diff(F);
% 
% y = randsample(length(L),1e6,'true',L);
% y = emp(y);
% [f, xi] = ksdensity(y);
% bar(xi,f);
% 
% 
% %plot(M(2:end),F,'LineWidth',4);
% title('Employment')
set(gca,'YTickLabel',[]);
set(gcf,'units','points','position',[10,10,500,300])
set(findall(gcf,'-property','FontSize'),'FontSize',16)

print('-dpng', 'figures/distributions.png');
